﻿#coding:utf-8
__author__ = 'Xiaodong.Yang'

"""
CopyRight(c)  FraPlus.Corp 2017
Date : 2017-06-15
"""

import base64

from fralog.FraLog import Fralog

import pycurl
from utils.utils import IP
import os

log = Fralog().getFileLog()
host = IP
port  = 8899

class MailClient(object):
    def __init__(self):
        super(MailClient).__init__()

    def send(self,email,order_no,total_amount):
        url2 = 'http://{0}:{1}/mail/?email={2}&order_no={3}&total_amount={4}'.format(host,port,email, order_no, total_amount)
        log.info(url2)
        c = pycurl.Curl()
        c.setopt(c.URL,url2)
        c.perform()
        log.info('向 %s 推送邮件'%(email))
        log.info('任务推送成功')

    def send_msg(self, email, title , msg):
        title = base64.b64encode(title.encode('gbk')).decode('gbk')
        msg = base64.b64encode(msg.encode('gbk')).decode('gbk')
        print(msg)
        url2 = 'http://{0}:{1}/mail?email={2}&title={3}&msg={4}'.format(host,port,email, title, msg)
        log.info(url2)
        c = pycurl.Curl()
        c.setopt(c.URL,url2)
        c.perform()
        log.info('向 %s 推送邮件'%(email))
        log.info('任务推送成功')

if __name__ == '__main__':
    client = MailClient()
    for i in range(1):
        msg = '请单击链接激活账号'
        client.send_msg('xiaodong.yang@unidt.com', 'Fra+账号激活', msg)